﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Windows.Forms;

public partial class manage_member_mange : System.Web.UI.Page
{
    public static int a = 0;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        a++;
        if (a % 2 == 1)
        {
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                System.Web.UI.WebControls.CheckBox c1 = (System.Web.UI.WebControls.CheckBox)(this.GridView1.Rows[i].FindControl("CheckBox1"));
                c1.Checked = true;
            }
            Button1.Text = "取消全选";
        }
        else if (a % 2 == 0)
        {
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                System.Web.UI.WebControls.CheckBox c1 = (System.Web.UI.WebControls.CheckBox)(this.GridView1.Rows[i].FindControl("CheckBox1"));
                c1.Checked = false;
            }
            Button1.Text = "全选";
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        DialogResult result = MessageBox.Show("请确认是否要删除选中的记录行？", "信息提示！", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
        if (result == DialogResult.OK)
        {
            DataClassesDataContext db = new DataClassesDataContext();
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                System.Web.UI.WebControls.CheckBox c1 = (System.Web.UI.WebControls.CheckBox)(this.GridView1.Rows[i].FindControl("CheckBox1"));
                if (c1.Checked)
                {
                    //string str = GridView2.Rows[i].Cells[0].Text;

                    string str1 = GridView1.DataKeys[i].Value.ToString();
                    //Response.Write(str1);
                    tb_Member cs = db.tb_Member.Single(a => a.UserName == str1);
                    db.tb_Member.DeleteOnSubmit(cs);
                    db.SubmitChanges();
                    //db.delete_table(int.Parse(str1));
                    //db.delete_stu(str1);

                }
            }
        }
        else { DialogResult.Cancel.Equals("true"); }
        GridView1.DataSourceID = "";
        if (ViewState["search"] == null)
        bind();
        
        
    }
    public void bind()
    {
        string connstr = ConfigurationManager.ConnectionStrings["a123"].ToString();
        SqlConnection sqlconn = new SqlConnection(connstr);
        string sqlstr = "select * from tb_Member";
        sqlconn.Open();
        SqlCommand sqlcom = new SqlCommand(sqlstr, sqlconn);
        SqlDataReader dr = sqlcom.ExecuteReader();
        GridView1.DataSource = dr;
        GridView1.DataBind();
        sqlconn.Close();
    }
}